﻿@{
    Layout = "~/Areas/Web/Views/Shared/_UserCenter.cshtml";
    ViewBag.Title = "个人信息";
}
@model Himall.Model.UserMemberInfo

<div class="box1 lh24">
    <div class="title bot-border">
        <h3 class="title_txt cur">修改密码</h3>
    </div>
    <div class="border-box">
        <div class="user-set userset-lcol">
            <div class="form">
                <div class="item">
                    <span class="label">旧密码：</span>
                    <div class="fl">
                        <input type="password" value="" id="old" name="userVo.realName" maxlength="20" class="itxt fl">
                        <span id="old_msg" class="prompt-06" style="padding-left:10px;"></span>
                    </div>
                </div>
                <div class="item">
                    <span class="label">新密码：</span>
                    <div class="fl">
                        <input type="password" value="" id="new" name="userVo.realName" maxlength="20" class="itxt fl">
                        <span id="new_msg" class="prompt-06" style="padding-left:10px;"></span>
                    </div>
                </div>
                <div class="item">
                    <span class="label">重复密码：</span>
                    <div class="fl">
                        <input type="password" value="" id="confirm" name="userVo.realName" maxlength="20" class="itxt fl">
                        <span class="prompt-06" id="confirm_msg" style="padding-left:10px;"></span>
                    </div>
                </div>
                <div class="item">
                    <span class="label">&nbsp;</span>
                    <div class="fl">
                        <a id="id_btn" class="btn-5" href="javascript:;">提交</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>

    //验证
    ; (function ($) {
        $("#old").focus();
        var stae1, stae2, stae3,
            fn = function (dom, d, callback, msg) {
                $.ajax({
                    type: 'post',
                    url: '@Url.Action("CheckOldPassword")',
                    data: 'password=' + d,
                    dataType: "json",
                    success: function (data) {
                        if (!data.success) {
                            callback(dom, data.success, msg, d);
                        } else {
                            $('#old_msg').html('');
                            $('#old').css({ borderColor: '#ccc' });
                            stae1 = $('#' + dom).val();
                        }
                    }
                });
            },
            handle = function (dom, data, msg, d) {
                if (data) {
                    stae1 = $('#' + dom).val();
                } else {
                    $('#' + dom).css({ borderColor: '#f60' });
                    $('#' + dom + '_msg').css({ color: '#f60' }).html(msg);
                    stae1 = '';
                }
            };
        $('#old').blur(function () {
            var d = $(this).val();
            fn('old', d, handle, '密码错误!');
        });
        $('#new').blur(function () {
            var d = $(this).val();
            if (d.length < 6) {
                $('#new').css({ borderColor: '#f60' });
                $('#new_msg').css({ color: '#f60' }).html('密码不能少于6位!');
                stae2 = '';
            } else {
                $('#new').css({ borderColor: '#ccc' });
                $('#new_msg').css({ color: '#ccc' }).html('');
                stae2 = d;
                if ($('#confirm').val() != '' && $('#confirm').val() == $('#new').val()) {
                    $('#confirm').css({ borderColor: '#ccc' });
                    $('#confirm_msg').css({ color: '#ccc' }).html('');
                    stae3 = d;
                }
            }
        });
        $('#confirm').blur(function () {
            var d = $(this).val();
            if (d == $('#new').val()) {
                $('#confirm').css({ borderColor: '#ccc' });
                $('#confirm_msg').css({ color: '#ccc' }).html('');
                stae3 = d;
            } else {
                $('#confirm').css({ borderColor: '#f60' });
                $('#confirm_msg').css({ color: '#f60' }).html('两次密码不一致!');
                stae3 = '';
            }
        });
        $('#id_btn').bind('click', function () {
            if ($("#old").val() == null || $("#old").val().length == 0) {
                $('#old').css({ borderColor: '#f60' });
                $('#old_msg').css({ color: '#f60' }).html('请输入密码!');
            }
            //console.log(stae1)
            if (!stae1) {
                $('#old').css({ borderColor: '#f60' });
                $('#old_msg').css({ color: '#f60' }).html('原密码输入错误!');
            }
            if (!stae2) {
                $('#new').css({ borderColor: '#f60' });
                $('#new_msg').css({ color: '#f60' }).html('密码不能少于6位!');
            }
            if (!stae3) {
                $('#confirm').css({ borderColor: '#f60' });
                $('#confirm_msg').css({ color: '#f60' }).html('两次密码不一致!');
            }
            if (stae1 && stae2 && stae3) {
                var loading = showLoading();
                $.ajax({
                    type: 'post',
                    url: '@Url.Action("ChangePassword")',
                    data: { "oldpassword": stae1, "password": stae3 },
                    dataType: "json",
                    success: function (data) {
                        loading.close();
                        if (data.success) {
                            $.dialog.succeedTips("密码修改成功！", function () {
                                $('#old').val('');
                                $('#new').val('');
                                $('#confirm').val('');
                                stae1 = '';
                                stae2 = '';
                                stae3 = '';
                            }, 2);
                        } else {
                            $.dialog.errorTips("保存失败！" + data.msg, '', 3);
                        }
                    }
                });
            }
        });
    }(jQuery));
</script>